﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Elements.Links
{
    /// <summary>
    /// 贝塞尔连线定义
    /// </summary>
    public class BezierLinkV3 : LinkBaseV2
    {
        /// <summary>
        /// 根据连接点的方位，调用贝塞尔曲线的控制点
        /// </summary>
        /// <param name="ori"></param>
        /// <param name="linkPt"></param>
        /// <returns></returns>
        Point GetCtlPoint(Point ori,ShapeBaseV2.ShapeLinkPoints linkPt)
        {
            switch (linkPt)
            {
                case ShapeBaseV2.ShapeLinkPoints.左:
                    return new Point(ori.X - 50, ori.Y);
                case ShapeBaseV2.ShapeLinkPoints.上:
                    return new Point(ori.X, ori.Y - 50);
                case ShapeBaseV2.ShapeLinkPoints.右:
                    return new Point(ori.X + 50, ori.Y);
                case ShapeBaseV2.ShapeLinkPoints.下:
                default:
                    return new Point(ori.X, ori.Y + 50);
            }
        }

        public override void Draw(Graphics g)
        {
            var startPoint = StartShape.GetLinkPoint(StartShapeLinkPoint);
            var endPoint = EndShape.GetLinkPoint(EndShapeLinkPoint);

            var ctlPoint1 = GetCtlPoint(startPoint,StartShapeLinkPoint);
            var ctlPoint2 = GetCtlPoint(endPoint, EndShapeLinkPoint);

            g.DrawBezier(new Pen(BackgroundColor, 2),
               startPoint,
               ctlPoint1,
               ctlPoint2,
               endPoint);
        }
    }
}
